import request from '@/utils/request';
import axios from 'axios';

// 登录方法
export function login(tenant, username, password, code, uuid) {
  const data = {
    tenant,
    username,
    password,
    code,
    uuid
  }
  return request({
    url: '/login',
    headers: {
      isToken: false,
      "tenant": data.tenant
    },
    method: 'post',
    data: data
  })
}

// 注册方法
export function register(data) {
  return request({
    url: '/register',
    headers: {
      isToken: false
    },
    method: 'post',
    data: data
  })
}

// 获取用户详细信息
export function getInfo() {
  return request({
    url: '/getInfo',
    method: 'get'
  })
}

// 退出方法
export function logout() {
  return request({
    url: '/logout',
    method: 'post'
  })
}

// 获取验证码
export function getCodeImg() {
  return request({
    url: '/captchaImage',
    headers: {
      isToken: false
    },
    method: 'get',
    timeout: 20000
  })
}

//获取用户信息
function getUserInfo () {
  const baseUrl = localStorage.getItem('baseUrl') || 'https://szjydjxmf.dfs.yelinksaas.com';
  const wsUrl = localStorage.getItem('wsAddress');
  const token = localStorage.getItem('Token') || 'eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJmQm9wV2otVTFIYjlTa0ZHMHZYQ1lRVVhkRkdDMGhXRTBkVjJCN1FaSl9ZIn0.eyJleHAiOjE3NDEzOTYxMTgsImlhdCI6MTczNjIxMjExOCwianRpIjoiYmJmYjViMWYtYmNkYS00NmIwLWFiNTItNWJkNmM0NWJiN2ExIiwiaXNzIjoiaHR0cDovLzE3Mi4xNi4wLjM6ODQxMS9hdXRoL3JlYWxtcy9lZGdlIiwiYXVkIjpbImFjY291bnQiLCJvY3MtY29udHJvbGxlciJdLCJzdWIiOiIzY2FiNTllMy0xNjI2LTQ0ZGYtOWNjMi1hYWU0ZDc3N2M2ZjIiLCJ0eXAiOiJCZWFyZXIiLCJhenAiOiJqaW5nemhpIiwic2Vzc2lvbl9zdGF0ZSI6ImUyMzU3NDBiLWVkNzgtNDU5Ni1hZTNhLTlhMWIwZmEwMTI4NCIsImFjciI6IjEiLCJyZWFsbV9hY2Nlc3MiOnsicm9sZXMiOlsi57O757uf6L-Q57u0Iiwib2ZmbGluZV9hY2Nlc3MiLCJ1bWFfYXV0aG9yaXphdGlvbiIsInVzZXIiLCJkZWZhdWx0LXJvbGVzLWVkZ2UiLCLnrqHnkIblkZgiXX0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX0sIm9jcy1jb250cm9sbGVyIjp7InJvbGVzIjpbIm9jcy1jb250cm9sbGVyLWFkbWluLXJvbGUiLCJvY3MtY29udHJvbGxlci1yZWFkLXJvbGUiXX19LCJzY29wZSI6InByb2ZpbGUgZW1haWwiLCJzaWQiOiJlMjM1NzQwYi1lZDc4LTQ1OTYtYWUzYS05YTFiMGZhMDEyODQiLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsIm5hbWUiOiLlhq_ngo7puY8iLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJmZW5neXAiLCJnaXZlbl9uYW1lIjoi5Yav54KO6bmPIiwiZmFtaWx5X25hbWUiOiIiLCJlbWFpbCI6ImZlbmd5cEB0ZXN0LmNvbSJ9.RBRHJEGMQr05n00L5k_qtrSvnSAkPdOIKCJLFcCW_R-qduqYEW4QR9gS_OHYijtWCo7RVJwkcn9cX4FW1Xb8RSTRbzysqNAB6LgbW1KN_sfxq6n-m19jbaGroRP8TwRo4yFc_LVcX4Xb1zUE-vFGbID4zKP487jywut-digGGvauM_Hx_FFtdf0zO2xqFT5imXSl3iwjZHUxjXGaeZ7Tp1c8mIqC5Cd9IMRLLrTQY80xd2_AlIs0LkHvRHhsfqtpyp6bOidPIcLuS-YRHkrri-Dz1QN-VnoZybMuDesxnv9RgD_LcnAV94gPnSvV4LkE6s3CEwnZ913lTolpTedKaw';
  return axios.get(
    baseUrl + '/factory/v1/api/v1/open/users/info/by/token',
    {
      headers:{
        Authorization:'Bearer ' + token
      }
    }
  )
}

//获取token传递给服务端
export function re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